import IDemo.Student;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class TestSort {
	public static void main(String[] args) {

               // TestComparable
                
                Student[] ss={new Student(3,"Zhaang","Compuer"),
                             new Student(3,"Zhaang","Mathematic"),
                             new Student(4,"Zha Li","Chinese"),
                             new Student(2,"Z Liu","Compuer"),
                             new Student(1,"Wu Zha","Physics")};
               Arrays.sort(ss);
               System.out.println("Student[] ss after sort");
               for(Student s:ss)
                   System.out.println(s);
               
               System.out.println("List<Student> get from Student[] ss ");
               System.out.println(Arrays.asList(ss));
               
               List<Student> ls=new LinkedList();
               ls.add(new Student(3,"Zhaang","Compuer"));
               ls.add(new Student(3,"Zhaang","Mathematic"));
               ls.add(new Student(4,"Zha Li","Chinese"));
               ls.add(new Student(2,"Z Liu","Compuer"));
               ls.add(new Student(1,"Wu Zha","Physics"));
               Collections.sort(ls);
                for(Student s:ls)
                   System.out.println(s);
               ls.remove(3);
               System.out.println("LinkedList ls after remove 3");
               for(Student s:ls)
                   System.out.println(s);
              
              //end Test Comparable
              
              //Test Comparator
              /*
              Student[] ss={new Student(3,"Chaang","Compuer"),
                             new Student(3,"Zhaang","Mathematic"),
                             new Student(4,"Zha Li","Chinese"),
                             new Student(2,"De Liu","Compuer"),
                             new Student(1,"Wu Zha","Physics")};
               Arrays.sort(ss,new Comparator<Student>()
                                       {                                       
                                          public int compare(Student o1, Student o2) {
                                          return  o1.getName().compareTo(o2.getName());  }
                                       });
               System.out.println("Student[] ss after sort");
               for(Student s:ss)
                   System.out.println(s);
               System.out.println("List<Student> get from Student[] ss ");
               System.out.println(Arrays.asList(ss));
               
               List<Student> ls=new LinkedList<>();
               ls.add(new Student(3,"Zhaang","Compuer"));
               ls.add(new Student(3,"Zhaang","Mathematic"));
               ls.add(new Student(4,"Zha Li","Chinese"));
               ls.add(new Student(2,"Z Liu","Compuer"));
               ls.add(new Student(1,"Wu Zha","Physics"));
               
               /* java8以前的匿名内部类的表达方式
               Collections.sort(ls,new Comparator<Student>()
                                       {                                       
                                          public int compare(Student o1, Student o2) {
                                          return  o1.getMajor().compareTo(o2.getMajor());
                                           
                                       }});
                */
               
               //java8新引入的lambda语句表达方式
               /*
               Collections.sort(ls,(Student o1,Student o2) -> o1.getMajor().compareTo(o2.getMajor()));
               
                System.out.println("LinkedList DataStructure");
               */
                /* java8以前的遍历表达方式  
                System.out.println("Old style---------");
                for(Student s:ls)
                   System.out.println(s);    */
                
                
                /* java8新引入的集遍历表达方式    
                System.out.println("java8 style---------");
                ls.forEach(System.out::println);  
                */
                
               /* 
               ls.remove(3);
               System.out.println("LinkedList ls after remove 3");
               for(Student s:ls)
                   System.out.println(s);  
               */
	}
}
